package com.example.transaction.publisher;

import com.example.transaction.config.RabbitMQConfig;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OrderExpirationPublisher {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void publishOrderExpiration(Integer orderId, long delay) {
        rabbitTemplate.convertAndSend(RabbitMQConfig.ORDER_EXPIRATION_EXCHANGE,
                RabbitMQConfig.ORDER_EXPIRATION_ROUTING_KEY,
                orderId,
                message -> {
                    message.getMessageProperties().setExpiration(String.valueOf(delay));
                    return message;
                });
    }
}
